{extend name="public:base" /}

{block name="content"}
<link rel="stylesheet" href="__CSS__/bootstrapValidator.min.css">
<link rel="stylesheet" href="__CSS__/AdminLTE.min.css">
<style type="text/css">
    input.error { border: 1px solid red; }
    label.error {
        background:url("./demo/images/unchecked.gif") no-repeat 0px 0px;

        padding-left: 16px;

        padding-bottom: 2px;

        font-weight: bold;

        color: #EA5200;
    }
    .f_g_box{
        flex-flow: row wrap;
    }
    label.checked {
        background:url("./demo/images/checked.gif") no-repeat 0px 0px;
    }
</style>
<div class="back_btn">
    <!-- 返回按钮 -->
    <button class="btn btn_color" type="button" style="outline: none;">
        <a href="{:url('index/index')}"><span class="glyphicon glyphicon-arrow-left" style="color:#3c8dbc;font-size: 18px;"></span></a>
    </button>
    <button type="button" class="btn btn-info btn-xs pull-right " style="margin: 10px 10px;">
        <a href="{:url('index')}">返回首页</a>
    </button>
</div>
<div class="row_box">
    <div class="col_box">
        <div class="box-header" data-original-title="" style="height: 30px;">
            <span><i class="glyphicon glyphicon-plus"></i>增加订单</span>
        </div>
        <div class="input_box">
            <form action="" id="commentForm" name="register" method="post">
                <div class="form-group f_g_box">
                    <label>姓名</label>
                    <input type="text" name="name" id="name">
                </div>
                <div class="form-group f_g_box">
                    <label>电话(妈妈)</label>
                    <input type="text" name="maphone" id="maphone" placeholder="请输入妈妈的电话">
                </div>
                <div><label>&nbsp;&nbsp;</label><input type="hidden"></div>
                <div class="form-group f_g_box">
                    <label>电话(家人)</label>
                    <input type="text" name="otherphone" id="otherphone">
                </div>
                <div><label>&nbsp;&nbsp;</label><input type="hidden"></div>
                <div class="form-group f_g_box">
                    <label>微信</label>
                    <input type="text" name="weixin" id="weixin">
                </div>
                <div><label>&nbsp;&nbsp;</label><input type="hidden"></div>
                <div class="form-group f_g_box">
                    <label>QQ</label>
                    <input type="text" name="qq" id="qq">
                </div>
                <div><label>&nbsp;&nbsp;</label><input type="hidden"></div>
                <div class="form-group f_g_box">
                    <label>预产期</label>
                    <input type="text"class="layui-input" name="yctime" id="yctime"  onclick="laydate({min:laydate.now()})" readonly >
                </div>
                <div><label>&nbsp;&nbsp;</label><input type="hidden"></div>
                <div class="form-group f_g_box">
                    <label>业务分类</label>
                    <select class="form-control" name="fenlei" id="fenlei">
                        <!--<option value="">请选择</option>-->
                        {volist name='fenlei' id='data'}
                        <option value="{$data.id}" {eq name="data.id" value="83"}selected{/eq} >{$data.name}</option>
                        {/volist}
                    </select>
                </div>
                <div><label>&nbsp;&nbsp;</label><input type="hidden"></div>
                <div class="form-group f_g_box">
                    <label>业务状态</label>
                    <select class="form-control" name="ywstate">
                        {volist name='state' id='data'}
                        <option value="{$data.id}" {$data.status} >{$data.name}</option>
                        {/volist}
                    </select>
                </div>
                <div class="tishi"><label>&nbsp;&nbsp;</label><input type="hidden"></div>

                <div class="form-group f_g_box">
                    <label>渠道</label>
                    <select class="form-control" name="qudao" id="qudao">
                        <option value="">请选择</option>
                        {volist name='qudao' id='data'}
                        <option value="{$data.id}">{$data.name}</option>
                        {/volist}
                    </select>
                </div>
                <div><label>&nbsp;&nbsp;</label><input type="hidden"></div>
                <div class="form-group f_g_box">
                    <label>区域</label>
                    <select class="form-control" name="area" id="area" onchange="loadRegion('area','parent_id','yiyuan','{:url('Ajax/region')}');">
                        <option value="">请选择</option>
                        {volist name='area' id="vo"}
                        <option value="{$vo.id}">{$vo.name}</option>
                        {/volist}
                    </select>
                </div>
                <div><label>&nbsp;&nbsp;</label><input type="hidden"></div>
                <div class="form-group f_g_box">
                    <label>收集医院</label>
                    <select class="form-control" name="yiyuan" id="yiyuan">
                        <option value="">请选择</option>
                        {volist name='yiyuan' id='data'}
                        <option value="{$data.id}">{$data.name}</option>
                        {/volist}
                    </select>
                </div>
                <div><label>&nbsp;&nbsp;</label><input type="hidden"></div>
                {eq name='$Think.session.admin_user.depar_id' value='1'}
                <div class="form-group f_g_box">
                    <label>医院渠道</label>
                    <select class="form-control" name="menzhen" id="menzhen">
                        <option value="">请选择</option>
                        {volist name='menzhen' id='data'}
                        <option value="{$data.id}">{$data.name}</option>
                        {/volist}
                    </select>
                </div>
                <div><label>&nbsp;&nbsp;</label><input type="hidden"></div>
                {/eq}
                <div class="form-group f_g_box">
                    <label>备注</label>
                    <textarea type="text" rows="3" id="qdbz" name="qdbz"></textarea>
                </div>
                <div class="btn_t">
                    <!--{:token('__hash__')}-->
                    <button type="submit" id="submit" >确定</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!-- 搜索 结束 -->
<!-- 列表 -->
{/block}

{block name="js"}
<script src="__JS__/jquery-2.2.3.min.js"></script>
<script type="text/javascript" src="__STATIC__/layui/layui.js"></script>

<script type="text/javascript" src="__JS__/calendar.js"></script>
<script type="text/javascript" src="__JS__/region.js"></script>
<!-- Bootstrap 3.3.6 -->
<script src="__JS__/bootstrap.min.js"></script>
<script src="__JS__/bootstrapValidator.min.js"></script>
<!-- iCheck -->
<script src="__JS__/language/zh_CN.js"></script>
<script type="text/javascript" src="__JS__/chachong.js"></script>

<script type="text/javascript">
    $(function () {
        layui.use(['laydate','layer'], function(){
            var laydate = layui.laydate;
            var layer = layui.layer;

            var start = {
                min: laydate.now()
                ,max: '2099-06-16 23:59:59'
                ,istoday: false
                ,choose: function(datas){
                    /*end.min = datas; //开始日选好后，重置结束日的最小日期
                    end.start = datas //将结束日的初始值设定为开始日*/
                }
            };

            document.getElementById('yctime').onclick = function(){
                start.elem = this;
                laydate(start);
                var yctime = $("#yctime");
                var bootstrapValidator = $("#commentForm").data('bootstrapValidator');
                bootstrapValidator.updateStatus('yctime', 'NOT_VALIDATED').validateField('yctime'); //错误提示信息变了
            }
        });


        $('#commentForm').bootstrapValidator({
            message: 'This value is not valid',
            feedbackIcons: {
            },
            fields: {
                name:    {  message: '用户名验证失败', validators: {notEmpty: {message: '用户名不能为空'}}},
                maphone: {  validators: {notEmpty: {message: '妈妈电话不能为空'},
                            stringLength: {min: 11, max: 11, message: '请输入11位手机号码'},
                            regexp: {regexp: /^1[3|5|8|7]{1}[0-9]{9}$/, message: '请输入正确的手机号码'}}},
                yctime:  {  validators: {notEmpty: {message: '预产期不能为空'},
                            date : {format : "YYYY-MM-DD", message : "预产期格式不正确"         }}},
                fenlei:  {  validators: {notEmpty: {message: '分类不能为空'}}},
                qudao:   {  validators: {notEmpty: {message: '渠道不能为空'}}},
                area:    {  validators: {notEmpty: {message: '区域不能为空'}}},
                yiyuan:  {  validators: {notEmpty: {message: '医院不能为空'}}},
                menzhen: {  validators: {notEmpty: {message: '医院渠道不能为空'}}}
            }
        });

        $(document).keyup(function(event){
            if(event.keyCode ==13){
                $("#submit").trigger("click");
            }
        });
        $("#commentForm").submit(function(ev){ev.preventDefault();});
        $("#submit").on("click", function(){
            var bootstrapValidator = $("#commentForm").data('bootstrapValidator');

//            if({$Think.session.admin_user.depar_id} == 1){
//                bootstrapValidator.enableFieldValidators('yiyuan', true);
//            }else{
//                bootstrapValidator.enableFieldValidators('yiyuan', false);
//            }

            if({$Think.session.admin_user.depar_id} == 1 && ({$Think.session.admin_user.adminid} != 107 ) ){
                bootstrapValidator.enableFieldValidators('area', true);
                bootstrapValidator.enableFieldValidators('yiyuan', true);
                bootstrapValidator.enableFieldValidators('menzhen', true);
            }else{
                bootstrapValidator.enableFieldValidators('area', false);
                bootstrapValidator.enableFieldValidators('yiyuan', false);
                bootstrapValidator.enableFieldValidators('menzhen', false);
            }

            bootstrapValidator.validate();
            if(bootstrapValidator.isValid()){

                $.ajax({
                    type: "POST",
                    url:  "{:url('add_list')}",
                    data: $('#commentForm').serialize(),
                    beforeSend:function(){
                        $(this).attr("disabled","false"); //禁止点击
                    },
                    success: function(msg){
//                        console.log(msg);
//                        alert(msg.status);
                        if(msg.status==1){
                            $('#submit').attr("disabled","false"); //禁止点击
                            layer.msg(msg.info, {icon: 1});
                            setTimeout(function(){
                                location.href="{:url('index/listing')}";
                            },3000); //延迟演示
                        }else{
                            layer.msg(msg.info, {icon: 2});
                            $('#submit').removeAttr("disabled"); //可以点击
                        }

                    }
                });
                return false;
            }else return ;
        });
    });
</script>
{/block}

